#include "Line2NodeShpFunc.h"

using SG::DataStructure::Common::Real;
using SG::Algebra::Matrixd;
using SG::FEMSolver::Element::Line2NodeShpFunc;

Line2NodeShpFunc::Line2NodeShpFunc ()
:NSet (), DNDxiSet ()
{}

/** @brief 计算积分点处形函数及形函数对参数坐标导数
 * 
 * 缓存各个积分点处的计算结果，避免下一次积分点循环时重复计算（内存换取计算时间）
 */

void Line2NodeShpFunc::Compute (const SG::DataStructure::FEM::IntegPointArray& integPoints)
{
    const auto nGauss = integPoints.size ();
    NSet.resize (nGauss);
    DNDxiSet.resize (nGauss);
    const Real half{0.5};
    for (std::size_t index = 0; index < nGauss; ++index)
    {
        const Real& xi{integPoints[index].m_x};

        NSet[index] = Matrixd (2, 1);
        NSet[index] (0, 0) = half * (1.0 - xi);
        NSet[index] (1, 0) = half * (1.0 + xi);


        DNDxiSet[index] = Matrixd (1, 2);
        DNDxiSet[index] (0, 0) = -1.0 * half;
        DNDxiSet[index] (0, 1) =  1.0 * half;

    }
}